function [neural_gas_map] = findClusters(neural_gas_map)
    codebook = neural_gas_map.codebook;
    link_matrix = neural_gas_map.topol.link_matrix;
    cluster_information = zeros(size(codebook,1),1);
    
    cluster=1;
    for i=1:size(codebook,1)
        unit = i;
        if (cluster_information(unit)==0)
            [cluster_ids,link_matrix] = getClusterIDs(unit,link_matrix);
            cluster_information(cluster_ids)=cluster;
            cluster = cluster + 1;
        end;
    end;
    neural_gas_map.unitClassInfo = cluster_information;
    return;        
            

    
function [cluster_ids, link_matrix] = getClusterIDs(unit,link_matrix)
    %Get cluster units from given links
    links = link_matrix(unit,:);
    
    link_matrix(unit,:)=-1;
    ids = 1:length(links);
    linkIDs = (links >= 0);
    ids1 = ids(linkIDs);
    

    %recursively traverse the link_matrix
    cluster_ids=ids1;
    for i=1:length(ids1);
    [ids2,link_matrix] = getClusterIDs(ids1(i),link_matrix);
        %link_matrix(ids2,:)=zeros(length(ids2),size(link_matrix,2))-1;
        cluster_ids = [cluster_ids ids2];
    end
    cluster_ids = [cluster_ids unit];
    return;
    
    
            
    
      